package com.mhs.dataclassification.processN;

import com.mhs.DTO.MySQLiteHelper;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class ProcessN_TongSoDVDL {
	private SQLiteDatabase database;
	private MySQLiteHelper dbHelper;
	
	public ProcessN_TongSoDVDL(Context context) {
		dbHelper = new MySQLiteHelper(context);
		//super();
	}

	public int getAllDataUnit(){
		int allDataUnit = getAllDataUnit_Table("phanloaithuoc") 
						+ getAllDataUnit_Table("thuoc");
		return allDataUnit;
	}
	
	public int getAllDataUnit_Table(String tableName){
		database = dbHelper.getReadableDatabase();
		int allDataUnit = 0;
		String sQuery = "select count(*) from " + tableName + ";";
		Cursor cursor = database.rawQuery(sQuery, new String [] {});
		if(cursor.getCount() == 0){
			allDataUnit = 0;
		}else if(cursor.getCount() == 1){
			cursor.moveToFirst();
			while (!cursor.isAfterLast()) {
				allDataUnit = cursor.getInt(0);
				break;
			}
			// Make sure to close the cursor
			cursor.close();
		}
		return allDataUnit;
	}
}
